<?php
if (!defined("HB_PATH")) die("Donot request this file directly!");

//Initial the Database, should be loaded only once while the starting of Hummingbird

include_once(constant("HB_INC_PATH") . "/ez_sql_core.php");
include_once(constant("HB_INC_PATH") . "/ez_sql_mysql.php");

$hbdb = new ezSQL_mysql();
if (!$hbdb->connect(constant("DB_USER"),constant("DB_PASS"),constant("DB_HOST"))) {
	hb_die("Cannot connect to Database!");
}

if (version_compare(mysql_get_server_info($hbdb->dbh), '4.1.0', '>=')){
	if (defined("DB_CHAR")) $db_char = constant("DB_CHAR");
	if (defined("DB_COLL")) $db_coll = constant("DB_COLL");
	$coll_query = "";
	if (!empty($db_char)) {
		$coll_query = "SET NAMES '$db_char'";
		if (!empty($db_coll)) {
			$coll_query .= " COLLATE '$db_coll'";
		}
	}
	if (!empty($coll_query)) $hbdb->query($coll_query);
}

if (!$hbdb->select(constant("DB_NAME"))) {
	hb_die("Unable to connect the DB \"" . constant("DB_NAME") . "\".");
}

function db_register_table($table_name) {
	global $hbdb;
	$hbdb->$table_name = constant("DB_PRE") . $table_name;
}
?>